<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>exists 查询 | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'query-dsl-exists-query.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-exists-query.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-exists-query.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/query-dsl-exists-query.html" rel="nofollow" target="_blank">../en/query-dsl-exists-query.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch 权威指南 [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="query-dsl.html">查询领域特定语言(Query DSL)</a></span>
»
<span class="breadcrumb-link"><a href="term-level-queries.html">词级查询</a></span>
»
<span class="breadcrumb-node">exists 查询</span>
</div>
<div class="navheader">
<span class="prev">
<a href="term-level-queries.html">« 词级查询</a>
</span>
<span class="next">
<a href="query-dsl-fuzzy-query.html">fuzzy 查询 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="query-dsl-exists-query"></a>exists 查询
</h2>
</div></div></div>

<p>返回包含一个字段索引值的文档。</p>
<p>由于各种原因，文档的字段可能不存在索引值：</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
源 JSON 中的字段为 <code class="literal">null</code> 或 <code class="literal">[]</code>
</li>
<li class="listitem">
字段在映射中有 <code class="literal">"index" : false</code> 的设置
</li>
<li class="listitem">
字段值的长度超过了映射中的 <code class="literal">ignore_above</code> 设置
</li>
<li class="listitem">
字段值格式不正确，并且在映射中定义了 <code class="literal">ignore_malformed</code>
</li>
</ul>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="exists-query-ex-request"></a>请求示例
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_search
{
    "query": {
        "exists": {
            "field": "user"
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/275.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="exists-query-top-level-params"></a><code class="literal">exists</code>的顶级参数
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">field</code>
</span>
</dt>
<dd>
<p>
(必须, string) 你想要搜索的字段的名称。
</p>
<p>
如果 JSON 值为 <code class="literal">null</code> 或 <code class="literal">[]</code>，则字段被视为不存在，而下面这些值将表明该字段确实存在:
</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
空字符串，比如 <code class="literal">""</code> 或 <code class="literal">"-"</code>
</li>
<li class="listitem">
数组中包含 <code class="literal">null</code> 和其他值，比如 <code class="literal">[null, "foo"]</code>
</li>
<li class="listitem">
字段映射中的自定义的 <a class="xref" href="null-value.html" title="null_value" rel="nofollow"><code class="literal">null-value</code></a>
</li>
</ul>
</div>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="exists-query-notes"></a>注意
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="find-docs-null-values"></a>查找缺少索引值的文档
</h4>
</div></div></div>
<p>
要查找缺少字段索引值的文档，请使用 <code class="literal">must_not</code> <a class="xref" href="query-dsl-bool-query.html" title="Boolean query">布尔查询</a> 和 <code class="literal">exists</code> 查询。
</p>
<p>
下面这个搜索返回缺少 <code class="literal">user</code> 字段索引值的文档。
</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_search
{
    "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field": "user"
                }
            }
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/276.console"></div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="term-level-queries.html">« 词级查询</a>
</span>
<span class="next">
<a href="query-dsl-fuzzy-query.html">fuzzy 查询 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>